package com.xiaotou.weibo;

import java.util.ArrayList;
import java.util.List;

import weibo4j.Weibo;

import com.xiaotou.db.pojo.SinaUser;
import com.xiaotou.db.pojo.WbUser;
import com.xiaotou.weibo.appData.AbstractAppOauthData;
import com.xiaotou.weibo.appData.SinaAppOauthData;
import com.xiaotou.weibo.impl.DbWeiboUser;
import com.xiaotou.weibo.impl.SinaWeiboClient;

public class WeiboFactory {
    public static WeiboClient createWeiboClient(WbUser wbUser) {
        if (wbUser instanceof SinaUser) {
            final Weibo weibo = new Weibo();
            final SinaAppOauthData sinaAppOauthData = new SinaAppOauthData();
            weibo.setOAuthConsumer(sinaAppOauthData.getConsumerKey(), sinaAppOauthData.getConsumerSecret());
            weibo.setOAuthAccessToken(wbUser.getAccesstoken(), wbUser.getAccesstokenserect());
            return new SinaWeiboClient(weibo);
        }
        return null;
    }
    
	public static AbstractAppOauthData getAppOauthData(String wbType) {
		return new SinaAppOauthData();
	}
	
	public static WeiboUser createWeiboUser(WbUser wbUser){
		return new DbWeiboUser(wbUser);
	}
	
	public static List<WeiboUser> createWeiboUsers(List<WbUser> wbUsers){
		final List<WeiboUser> weiboUsers = new ArrayList<WeiboUser>();
		for(WbUser wbUser: wbUsers) {
			weiboUsers.add(createWeiboUser(wbUser));
		}
		return weiboUsers;
	}
}
